package com.tuanzi.loan.workflow.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.tuanzi.loan.business.entity.CurrentUser;
import com.tuanzi.loan.workflow.entity.TodoReadLog;
import com.tuanzi.loan.workflow.repository.TodoReadLogRepository;
import com.tuanzi.loan.workflow.service.TodoReadLogService;

/**
 * @author Ray
 * @date 2018/01/16
 */
@Service
@Transactional
public class TodoReadLogServiceImpl implements TodoReadLogService {

	@Autowired
	private TodoReadLogRepository todoReadLogRepository;

	@Override
	public void read(String procInstId, String taskId) {
		TodoReadLog todoReadLog = todoReadLogRepository.findByProcInstIdAndTaskId(procInstId, taskId);
		if (todoReadLog == null) {
			todoReadLog = new TodoReadLog();
			todoReadLog.setAccount(CurrentUser.get().getAccount());
			todoReadLog.setProcInstId(procInstId);
			todoReadLog.setTaskId(taskId);
			todoReadLogRepository.save(todoReadLog);
		}
	}
}
